program montecarlo
  real, parameter :: actual_pi = 3.14159265359
  real :: calc_pi
  integer :: total, cnt
  real :: x, y
  integer, dimension(12) :: seed
  integer :: i

  call system_clock(seed(1))
  call random_seed(put=seed)
  print *, "Enter the number of trials"; read *,total
  do i=1,total
    call random_number(x)
    call random_number(y)
    x=2*x
    y=2*y
    if(x**2 + y**2 < 4.0) then!if the point lies inside the quater circle
      cnt = cnt + 1
    end if
  end do
  calc_pi = 4.0 * real(cnt)/real(total)
  print *,"pi=",calc_pi
  print *,"error(%)=", (actual_pi - calc_pi)*100.0/actual_pi
end program

